//
//  RAboutViewController.m
//  Riji
//
//  Created by  on 2022/8/17.
//

#import "RAboutViewController.h"
#import "RMineCell.h"
#import "RAboutHeader.h"
#import "SWPrivacyViewController.h"

@interface RAboutViewController()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *data;
@property (nonatomic, strong) RAboutHeader *header;
@end
@implementation RAboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}
- (void)initUI
{
    self.title = LS(@"关于我们");
    self.data = @[@[@"软件更新",@"用户协议",@"隐私政策"],@[@"好评鼓励"]];
    self.header = [RAboutHeader loadFromXIB];
    
    [self.tableView registerNib:[RMineCell nib] forCellReuseIdentifier:[RMineCell ID]];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  [self.data[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RMineCell *cell = [tableView dequeueReusableCellWithIdentifier:[RMineCell ID]];
    NSArray *array = self.data[indexPath.section];
    NSString *str = array[indexPath.row];
    cell.type = RMineCellTypeInfo;
    cell.name.text = LS(str);
    cell.line.hidden = indexPath.row == [array count] - 1;
    return  cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return section == 0 ? 10 : 210;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return  section == 0 ? self.header.frame.size.height : 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
        view.backgroundColor = [UIColor colorWithHexString:@"#F7F7F7"];
        return view;
    }else{
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 210)];
        UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 172, SCREEN_WIDTH, 18)];
        lbl.text = LS(@"版权所有:xxx科技有限公司");
        lbl.textHexColor = @"#999999";
        lbl.font = [UIFont systemFontOfSize:13];
        lbl.textAlignment = NSTextAlignmentCenter;
        [view addSubview:lbl];
        return view;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return  self.header;
    }
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * str = self.data[indexPath.section][indexPath.row];
    if ([str isEqualToString:@"软件更新"]) {
        return [RLHud msg:LS(@"app 暂未上线")];
    }else if([str isEqualToString:@"用户协议"] || [str isEqualToString:@"隐私政策"]){
        SWPrivacyViewController *vc   = [SWPrivacyViewController new];
        vc.title = LS(@"隐私政策");
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([str isEqualToString:@"好评鼓励"]){
        return [RLHud msg:LS(@"app 暂未上线")];
    }
}

@end
